package com.example.demo;

import android.graphics.Bitmap;
import android.util.Log;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

public class MyImageCache implements ImageLoader.ImageCache {
    final int MAX_SIZE = 10 * 1024 * 1024;

    private LruCache<String, Bitmap> lruCache;

    public MyImageCache(){
        lruCache = new LruCache<String, Bitmap>(MAX_SIZE){
            @Override
            protected int sizeOf(String url, Bitmap bitmap) {
//                return bitmap.getByteCount();
                return bitmap.getRowBytes() * bitmap.getHeight();
            }
        };
    }

    @Override
    public Bitmap getBitmap(String url) {
        Log.e("MyImageCache", "getBitmap url = " + url);
        return lruCache.get(url);
    }

    @Override
    public void putBitmap(String url, Bitmap bitmap) {
        Log.e("MyImageCache", "putBitmap url = " + url);
        lruCache.put(url, bitmap);
    }
}
